﻿using Encryptionibrary;
using Prism.Ioc;
using Prism.Mvvm;
using System;
using TransformerSystem.Core;
using TransformerSystem.UI;

namespace TransformerSystem.Shell.ViewModels
{
    public class MainWindowViewModel : ViewModelBase, IWindowAware
    {
        /// <summary>
        /// 注册类
        /// </summary>
        Registerpad registerpad = new Registerpad();
        private string _title = "全自动变压器综合测试系统";

        public MainWindowViewModel(IContainerExtension container) : base(container)
        {
        }

        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        } 

        public bool CanClosing() => true;

        public void Initialized()
        {
            SystemGlobal.MachineID = GetMachineID();
            Logger.Error(new Exception("测试异常日志"));
        }
        public void Closed()
        {

        }
        /// <summary>
        /// 获取机器码
        /// </summary>
        /// <returns></returns>
        string GetMachineID()
        {
            string machineID = string.Empty;
            try
            {
                //获取机器码方法
                var id = registerpad.GetMachineCode();
                if (string.IsNullOrEmpty(id)) throw new Exception();
                machineID = id;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
            return machineID;
        }
    }
}
